var app = getApp();
Page(Object.assign({},{
    data:{
        curPage : "/zofui_sales/fenxiao/goods",
        page : {
            isend : false,
            doing : false,
            doo : 'fenxiao',
            pdata : {
                op : 'indexlist',
                page : 1,
                status : 0,
                key : '',
            },
            waitf : 0,
            nodataf : 0,
        },
        datalist : [],
        Menu: [{
            url: "/zofui_sales/pages/index/index",
            iconPath: "https://img11.360buyimg.com/ddimg/jfs/t1/66538/19/4014/3269/5d2351f9E53638303/d16ba3ba1f225e55.png",
            selectedIconPath: "https://img11.360buyimg.com/ddimg/jfs/t1/66538/19/4014/3269/5d2351f9E53638303/d16ba3ba1f225e55.png",
            title: "首页",
            type: "tabbar"
        }, {
            url: "/zofui_sales/fenxiao/goods",
            iconPath: "https://img11.360buyimg.com/ddimg/jfs/t1/76564/29/4072/4005/5d235934E9e4fec12/485ebe5e6f2b173f.png",
            selectedIconPath: "https://img11.360buyimg.com/ddimg/jfs/t1/53034/40/4498/4044/5d235938E08362533/0b26e6d2c077df6b.png",
            title: "销售"
        }, {
            url: "/zofui_sales/fenxiao/bill",
            iconPath: "https://img11.360buyimg.com/ddimg/jfs/t1/49710/34/4519/3981/5d235a12E2cc284ad/a4a02c22c99b4b61.png",
            selectedIconPath: "https://img11.360buyimg.com/ddimg/jfs/t1/34162/25/14452/4622/5d235a15E1e64565f/3900800ba49583a9.png",
            title: "资金",
        }, {
            url: "/zofui_sales/fenxiao/user",
            iconPath: "https://img11.360buyimg.com/ddimg/jfs/t1/45769/18/4567/6267/5d235b21Efff10c3e/507efc3f920d8740.png",
            selectedIconPath: "https://img11.360buyimg.com/ddimg/jfs/t1/72323/28/3988/6330/5d235b25E127fda9d/ecbb0c9f41cf8633.png",
            title: "结算中心"
        }],
        isIPX : app.globalData.isIPX,
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onLoad:function(options){
        var self = this;
        var uid = options.uid ? options.uid : '';
        self.setData({
            options : options,
        });
        app.com.auth(function(user){
            app.com.getPage(self,self.data.page,20,function(res){
                var data = res.data.data;
                self.setData({
                   datalist : data.list,
                   Pagetheme : res.data.data.params.style,
                   params : res.data.data.params,
                },function(){
                    self.setData({
                        inited : true,
                    });
                });
                
                for (var i = 0; i < self.data.Menu.length; i++) {
                    if( self.data.Menu[i].title == '个人中心' && res.data.data.params.pfuser == 1 ){
                        self.data.Menu.splice(i,1);
                        i--;
                    }
                    if( self.data.Menu[i].title == '销售' && res.data.data.params.pfs == 1 ){
                        self.data.Menu.splice(i,1);
                        i--;
                    }
                }
                
                self.setData({
                    Menu : self.data.Menu
                })

                wx.setNavigationBarTitle({
                  title:  res.data.data.params.goodbname,
                });

            },false,function(res){
                if( res.data.errno == 3 ){
                    app.com.confirm(res.data.message,function(){
                        var tourl = '/zofui_sales/ucard/buycard';
                        wx.navigateTo({
                          url: tourl
                        });
                        self.setData({
                            reload : 1,
                        });
                    },function(){
                         var pages = getCurrentPages();
                         if( pages.length > 1 ){
                            wx.navigateBack();
                         }else{
                            var tourl = '/zofui_sales/pages/index/index?zfid='+options.zfid;
                            wx.switchTab({
                              url: tourl
                            });
                         }
                    },'取消','购买会员');
                }else if( res.data.errno == 4 ){
                    app.com.alert(res.data.message,function(){
                        var tourl = '/zofui_sales/fenxiao/joinPartner';
                        wx.navigateTo({
                          url: tourl
                        });
                    })
                }else{
                    app.com.alert(res.data.message);
                }
            });
        });
       
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: self.data.article.title,
            path: '',
            imageUrl : self.data.article.img,
        }
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.setData({
            datalist : [],
            isdown : true,
            'page.pdata.page' : 1,
            'page.isend' : false,
            'page.waitf' : 0,
            'page.nodataf' : 0,
            'page.pdata.isinit' : 1,
        });
        this.onLoad( this.data.options );
        this.setData({
            isdown : false,
        });
        wx.stopPullDownRefresh();
    },
    comfirm(e){
        this.setData({
            'page.pdata.key' : e.detail.value,
            datalist : [],
            'page.pdata.page' : 1,
            'page.isend' : false,
            'page.doing' : false,
        })
        this.onReachBottom();
    },
    getPoster(e){
        var self = this;
        app.com.http('poster','POST',{op:'goods',gid:e.currentTarget.dataset.id},0,true,'','',function(res){
            if (!res.data.errno && res.data ) {
                wx.previewImage({
                    urls : [res.data.data.url]
                })
            }else{
                app.com.toast(res.data.message);
            }
        });
    },
    onReachBottom : function(){
        var self = this;
        app.com.getPage(self,self.data.page,20,function(res){
            self.setData({
                datalist : self.data.datalist.concat(res.data.data.list)
            });
        });
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },

}))